extends Panel

var collect_type = ""
var watch_status = ""

func _ready():
	$StatusContainer/WantWatchButton.group.connect("pressed",self,"on_watch_status_change")
	pass


func on_watch_status_change(btn):
	watch_status = btn.text

func _on_Cancel_pressed():
	self.hide()
	pass


func _on_Save_pressed():
	Global.dataJson[collect_type][$ZpName.text] = {"info":$ZpInfo.text,"status":watch_status}
	var file = File.new()
	if OS.get_name() == "Android":
		if Global.android_save_mode == Global.AndroidSaveMode.user:
			file.open("user://data.json",File.WRITE_READ)
			file.store_string(to_json(Global.dataJson))
			file.close()
		elif Global.android_save_mode == Global.AndroidSaveMode.sdcard:
			file.open(Global.android_sdcard_path,File.WRITE_READ)
			file.store_string(to_json(Global.dataJson))
			file.close()
	else:
		if Global.save_path_mode == Global.SavePathMode.user:
			file.open("user://data.json",File.WRITE_READ)
		elif Global.save_path_mode == Global.SavePathMode.exe:
			file.open(OS.get_executable_path().get_base_dir() + "/data.json",File.WRITE_READ)
		file.store_string(to_json(Global.dataJson))
		file.close()
	pass

func on_edit_show(type,btn_text):
	collect_type = type
	$ZpName.text = btn_text
	$ZpInfo.text = Global.dataJson[type][btn_text]["info"]
	var s = Global.dataJson[type][btn_text]["status"]
	match s:
		"在看":
			$StatusContainer/WatchButton.pressed = true
		"想看":
			$StatusContainer/WantWatchButton.pressed = true
		"看过":
			$StatusContainer/WatchedButton.pressed = true
		"抛弃":
			$StatusContainer/DropButton.pressed = true
	self.show()
	pass
